This tutorial will guide you through the process of deploying and interact an ERC-20 contract using the edexaJS library.
Prerequisite
- Getting Faucet: Before deploying an ERC-20 contract, you'll need testnet EDX coin to cover transaction costs. You can use a faucet to obtain test EDX Coin for the edexa network. Faucet Link
- Node Version: Ensure that your Node.js version is greater than 16.
2. Obtaining Private Key
To interact with the edexa network, you'll need a private key. Here's how you can obtain one:
Using Wallets like Metamask
- Open your preferred Ethereum wallet, such as Metamask or Trust Wallet.
- Navigate to the account settings or account details section.
- Look for an option like "Export Private Key" or "View Private Key."
- Copy the private key to your clipboard.
- For Metamask users, you can refer to the official guide: How to export an account's private key.
Note: Ensure that the account from which you are obtaining the private key is associated with the edexa network
Important: Never share your private key publicly, and handle it with the utmost care. It's recommended to use a separate account or wallet for testing purposes.
3. Installing the edexaJS Package
Use npm to install the edexaJS package:
npm install @edexa/edexajs
4. Creating Signer using edexaJS
In your code, import the EdexaClient
and create a signer with your private key:
import { EdexaClient } from "@edexa/edexajs";
const edexaClient = new EdexaClient();
const privateKey = "your actual private key here"; // Always handle with care!
const signer = edexaClient.createWalletSigner(privateKey);
5. Deploying ERC-20 Contract
Use the createContractERC20
function to deploy an ERC-20 contract. It returns the newly deployed contract address:
async function deployERC20Contract() {
const erc20Arg = {
name: "YourTokenName",
symbol: "YTN",
supply: 1000000, // Initial total supply
};
const erc20Contract = await edexaClient.createContractERC20(erc20Arg, signer);
contractAddress = erc20Contract.address;
}
6. Interacting with the Deployed Contract
To interact with the deployed ERC-20 contract, use the getERC20Instance
function to obtain an instance. Then, use various functions like getBalance
:
// pass the contractAddress that we got from previous point
const erc20 = edexaClient.getERC20Instance(contractAddress);
const address = "Address you want to find balance off";
const balance = await erc20.getBalance(address);
You can find the code sample here
Refer to the edexaJS documentation for more functions and details.